﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using DG.Tweening;

public class HeroCardData
{
    public string icon;
    public int lv;
}
public class HeroCard : MonoBehaviour , IPointerDownHandler,IPointerUpHandler,IDragHandler, IPointerEnterHandler,IPointerExitHandler{
    private Image _image;
    private Text _lv;
    HeroCardData _hero;
    HeroCardPanel _panel;
    private Vector3 _downPos;
    void Awake() {
        _image = this.GetComponent<Image>();
        _lv = transform.Find("lv").GetComponent<Text>();
    }
    public void SetPanel(HeroCardPanel panel)
    {
        this._panel = panel;
    }
    Sprite GetSprite(string s)
    {
        return null;
    }
    public void SetViewData(HeroCardData data)
    {
        _hero = data;
        //this._image.sprite = GetSprite(data.icon);
        this._lv.text = data.lv.ToString();
    }
    public Vector3 PointerDownTranPos {
        get { return _downPos; }
    }
    public HeroCardData HeroData
    {
        get
        {
            return _hero;
        }
    }
    public void OnPointerDown(PointerEventData eventData)
    {
        _downPos = transform.localPosition;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        _panel.OnDragCardEnd(eventData,this);
    }

    public void OnDrag(PointerEventData eventData)
    {
        //update other
        _panel.OnDragCard(eventData,this);
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        this._image.CrossFadeColor(Color.gray,0.15f,true,true);
        this.transform.localScale = new Vector3(1.1f,1.1f,1);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        this._image.CrossFadeColor(Color.white, 0.15f, true, true);
        this.transform.localScale = Vector3.one;
    }

    public void OnAnimateMoveTo(Vector3 to,float angle)
    {
        DOTween.Kill(transform);
        transform.DOLocalMove(to, 0.35f);
        transform.DORotate(new Vector3(0,0,angle), 0.35f);
    }

}
